{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cad6eae8",
   "metadata": {},
   "source": [
    "——————————————————————————\n",
    "\n",
    "* 本学习记录人：林涵萩\n",
    "* 记录时间：2021-11-16\n",
    "* week12\n",
    "* 参考文档：\n",
    "> 1. [python官方文档](https://www.python.org/doc/)\n",
    "> 2. [许老师博客](https://www.cnblogs.com/xuzhichao)\n",
    "\n",
    "——————————————————————————"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3ad027f",
   "metadata": {},
   "source": [
    "## 本周学习内容\n",
    "\n",
    "### 1. 认识列表（序列数据）\n",
    "\n",
    "\n",
    "\n",
    "### 3. 列表的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ba4a797",
   "metadata": {},
   "source": [
    "## 1. 认识[列表list](https://docs.python.org/3/tutorial/introduction.html#lists)\n",
    "\n",
    "* 最通用的是list，它可以写成方括号之间以逗号分隔的值（项）的列表。列表可能包含不同类型的项目，但通常这些项目都具有相同的类型。\n",
    "\n",
    "> 1. 列表的形式：括号之间逗号可以分割的值：[value1,value2,value3....]\n",
    "> 2. 列表可以索引（index）和切片（slice）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f43e22e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaofeng'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考：如果要存一些例如一个班、一堆用户的名字，怎么存？\n",
    "\n",
    "# 用字符串来存（字符串过长时操作起来非常之不方便）\n",
    "stu_names = \"Ziqi|Xiaofeng|Lihua\"\n",
    "stu_names[5:13]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eeb7baf1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaofeng'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表是由逗号隔开的一整个内容作为整体\n",
    "stu_names_list = [\"Ziqi\",\"Xiaofeng\",\"Lihua\"]\n",
    "stu_names_list[1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d78edc8b",
   "metadata": {},
   "source": [
    "### 2. 列表的取值（index）和切片（slice）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73bdb3ec",
   "metadata": {},
   "source": [
    "```\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "         0       1       2       3\n",
    "        -4       -3       -2       -1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "376e210b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e95f0915",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack Mary\n"
     ]
    }
   ],
   "source": [
    "# 取值\n",
    "print(names[3],names[-3])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9bcbeea6",
   "metadata": {},
   "source": [
    "> 2. 切片（slice）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a05272d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mary', 'Jan']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ce1489a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mary', 'Jan']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bc6de1af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e818b37f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "aaf6a78e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8538bdb2",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Jan']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5de0296",
   "metadata": {},
   "source": [
    "### 3. 列表的一般方法\n",
    "\n",
    "> 1. 列表的增加\n",
    "> 2. 列表的删除\n",
    "> 3. 列表的修改\n",
    "> 4. 列表的查询（如上 取值和切片）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "bced7b74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "63ce9985",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)\n",
    "# 因为列表可以存不同类型的数据（object），增加一个object到末尾"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4340b3f",
   "metadata": {},
   "source": [
    "> 1. 列表的增加\n",
    ">> 1. append(object, /) method of builtins.list instance\n",
    "    **Append object to the end of the list.**\n",
    ">> 2. insert(index, object, /) method of builtins.list instance\n",
    "    **Insert object before index.**\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c35af819",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "12dde329",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'Lihua']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "07d2fa18",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Xiaoming\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2ae087a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jan', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ee438a64",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d0493dd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(2,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "07c7eb7e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Alex', 'Jan', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80cd8fdc",
   "metadata": {},
   "source": [
    "> 2. 列表的删除\n",
    "\n",
    ">> 1. remove()-->remove(value, /)-->Remove first occurrence of value.-->（注意）Raises ValueError if the value is not present.\n",
    ">> 2.pop()--> L.pop([index]) --> 移除指定索引值并返回移除的值 --> （注意）Raises IndexError if list is empty or index is out of range，如果pop()index不写，将移除最后一个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e8ac28bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 1. 列表可以共同出现一些值      \n",
    "# 2. 共同出现的值，删除第一个\n",
    "help(names.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a8a9932c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "names.remove('Jan')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "0e5a4461",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "b271581c",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-42-9e7dde056fcc>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# 思考：如果这个值不存在 remove会怎样？-->\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mnames\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'yiming'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "# 思考：如果这个值不存在 remove会怎样？-->list.remove(x): x not in list\n",
    "names.remove('yiming')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "db10cc0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 删除remove使用的正确方法\n",
    "if 'yiming' in names:\n",
    "    names.remove('yiming')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "395516b9",
   "metadata": {},
   "source": [
    "--------------------------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "76930486",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 对于初学者，help非常有用\n",
    "help(names.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a2460179",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jack', 'Lihua', 'Xiaoming']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "a3fdfb24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Xiaoming'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. pop()      index不写 ：删除最后一个值，对比记忆append()\n",
    "names.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "17a2e597",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Mary', 'Jack', 'Lihua']"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "fb42ca6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Mary'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. index   写pop() ：删除指定索引位置的值\n",
    "\n",
    "names.pop(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "6aceccf0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "pop index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-49-ff19dc69555f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnames\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: pop index out of range"
     ]
    }
   ],
   "source": [
    "names.pop(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "6fda955b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a8fd4f98",
   "metadata": {},
   "outputs": [],
   "source": [
    "index = 3\n",
    "if index < len(names):\n",
    "    names.pop(index)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ea7fe64",
   "metadata": {},
   "source": [
    "> 5. 查询数量 count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "11c13937",
   "metadata": {},
   "outputs": [],
   "source": [
    "squares = [88,87,90,88,78,90,96,98,95,95,88]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "8bb2f9d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[88, 87, 90, 88, 78, 90, 96, 98, 95, 95, 88]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "1b27ef78",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function count:\n",
      "\n",
      "count(value, /) method of builtins.list instance\n",
      "    Return number of occurrences of value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(squares.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "c5bab20a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(88)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "45e30454",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function index:\n",
      "\n",
      "index(value, start=0, stop=9223372036854775807, /) method of builtins.list instance\n",
      "    Return first index of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(squares.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "7816c257",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.index(90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0d5bef33",
   "metadata": {},
   "outputs": [],
   "source": [
    "squares.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "e1373cf9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[78, 87, 88, 88, 88, 90, 90, 95, 95, 96, 98]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "378536d1",
   "metadata": {},
   "source": [
    "## 5. 课后作业\n",
    "\n",
    "> 1. 用表格总结列表的所有方法，如上表格所示\n",
    "> 2. 课本第二章列表的三个项目实践\n",
    ">> * 其中，三个项目的知识点：1. 可能涉及用户输入。2. 一定涉及列表切片。3. 一定涉及列表的方法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8f952579",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function clear:\n",
      "\n",
      "clear() method of builtins.list instance\n",
      "    Remove all items from list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.clear)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b8482292",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function copy:\n",
      "\n",
      "copy() method of builtins.list instance\n",
      "    Return a shallow copy of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.copy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d8455dea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function count:\n",
      "\n",
      "count(value, /) method of builtins.list instance\n",
      "    Return number of occurrences of value.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0fdfdae9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function extend:\n",
      "\n",
      "extend(iterable, /) method of builtins.list instance\n",
      "    Extend list by appending elements from the iterable.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.extend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "82103312",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function index:\n",
      "\n",
      "index(value, start=0, stop=9223372036854775807, /) method of builtins.list instance\n",
      "    Return first index of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c167d96b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function reverse:\n",
      "\n",
      "reverse() method of builtins.list instance\n",
      "    Reverse *IN PLACE*.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b5370779",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function sort:\n",
      "\n",
      "sort(*, key=None, reverse=False) method of builtins.list instance\n",
      "    Sort the list in ascending order and return None.\n",
      "    \n",
      "    The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n",
      "    order of two equal elements is maintained).\n",
      "    \n",
      "    If a key function is given, apply it once to each list item and sort them,\n",
      "    ascending or descending, according to their function values.\n",
      "    \n",
      "    The reverse flag can be set to sort in descending order.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.sort)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61a657ac",
   "metadata": {},
   "source": [
    "|序号  |    列表的方法|语法|用法|注意事项|\n",
    "| ---- | ---- | ---- | ---- | ---- |\n",
    "| 1. |    append()|     L(list).append(object) |    Append object to the end of the list   |\n",
    "| 2. |    insert()|     L.insert(index, object) |    Insert object before index    |\n",
    "| 3. |  remove()|     L.remove(value)|  remove first occurrence of value|（注意）Raises ValueError if the value is not present|\n",
    "| 4. |    pop()|      L.pop([index])| 移除指定索引值的内容并返回移除的值，如果pop()index不写，将移除最后一个值|(注意)Raises IndexError if list is empty or index is out of range|\n",
    "| 5. |   clear()|     L.clear()| Remove all items from list.|\n",
    "| 6. |  copy()|       L.copy()|Return a shallow copy of the list.\n",
    "| 7. |  count()|     L.count(value)| Return number of occurrences of value.|\n",
    "| 8. |  extend()|    L.extend(iterable)|Extend list by appending elements from the iterable.|\n",
    "| 9. |  index()|    L.index(value, start=0, stop=9223372036854775807)| Return first index of value.| Raises ValueError if the value is not present.|\n",
    "| 10. |  reverse()|  L.reverse()|Reverse * IN PLACE * |\n",
    "| 11. | sort()|  L.sort(* , key=None, reverse=False)|Sort the list in ascending order and return None.|The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).If a key function is given, apply it once to each list item and sort them,ascending or descending, according to their function values.The reverse flag can be set to sort in descending order.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c23039b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1697ee7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a77ffca0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:Milliways\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1f09045b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "750873d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "on tap\n"
     ]
    }
   ],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "new_phrase =  ''.join(plist[1:3])\n",
    "new_phrase =  new_phrase + ''.join([plist[5],plist[4],plist[7],plist[6]])\n",
    "\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "dcd68234",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters:\n",
    "    print('\\t',char)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "687e701b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\t M\n",
      "\t a\n",
      "\t r\n",
      "\t v\n",
      "\t i\n",
      "\t n\n",
      "\n",
      "\t\t A\n",
      "\n",
      "\t\t\t a\n",
      "\t\t\t r\n",
      "\t\t\t a\n",
      "\t\t\t n\n",
      "\t\t\t o\n",
      "\t\t\t i\n",
      "\t\t\t d\n",
      "\t\t\t  \n"
     ]
    }
   ],
   "source": [
    "paranoid_android = \"Marvin,the Paranoid Android\"\n",
    "letters = list(paranoid_android)\n",
    "for char in letters[:6]:\n",
    "    print('\\t',char)\n",
    "print()\n",
    "for char in letters[-7]:\n",
    "    print('\\t'*2,char)\n",
    "print()\n",
    "for char in letters[12:20]:\n",
    "    print('\\t'*3,char)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
